package jeulin.mobile.view;

import jeulin.mobile.R;
import jeulin.mobile.BDD.Appart;
import jeulin.mobile.BDD.Bloc;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.GridView;

public class BlocView extends Activity{
	private Bloc bloc;
	private GridView gridBloc;

	public BlocView(Context ctxt, Bloc p_bloc){
		this.bloc = p_bloc;
	}
	
	public void generateInterface(Context ctxt){
		gridBloc = new GridView(ctxt);
		gridBloc.setNumColumns(bloc.getNbCol());
		
		for(int i=0; i<bloc.getNbBoite() ; ++i){
			LayoutInflater inflater = getLayoutInflater();
			View v = (View) inflater.inflate(R.layout.boite, null);
			
			Appart a = bloc.getApparts().get(i);
			//remplissage des champs de la boite aux lettres
			EditText posBloc = (EditText)v.findViewById(R.id.positionBloc);
			posBloc.setText(a.getPlaceBaL());
			
			EditText posInter = (EditText)v.findViewById(R.id.positionInter);
			posInter.setText(a.getPlaceInter());
			
			EditText semPose = (EditText)v.findViewById(R.id.semainePose);
			semPose.setText(a.getPose());
			
			EditText semRel = (EditText)v.findViewById(R.id.semaineReleve);
			semRel.setText(a.getReleve());
			
			EditText nom = (EditText)v.findViewById(R.id.nom);
			nom.setText("");
			
			//ajout de la boitre au bloc
			gridBloc.addView(v);
		}
		setContentView(gridBloc);
	}
}
